
<?
	  include("/inc/header.html") {}
    ?>
<div style="margin-left: 0px;">

	<!--BEGIN CONTENT-->

			<div class="panel ">
				<div class="panel-body pan">

					<div class="row" style="margin-bottom: 10px;">
						<div class="col-lg-6"
							style="width: 320px; float:left; margin-right:-20px; display:inline;">
							<label for="inputUsername" class="col-md-3 control-label">中文名称</label>
							<div class="col-md-9">
								<div class="input-icon">
									<input id="nameZh" type="text" class="form-control" value="" />
								</div>
							</div>
						</div>
						<div class="col-lg-6"
							style="width: 320px; float:left; margin-right:-20px; display:inline;">
							<label for="inputUsername" class="col-md-3 control-label">英文名称</label>
							<div class="col-md-9">
								<div class="input-icon">
									<input id="nameEn" type="text" class="form-control" value="" />
								</div>
							</div>
						</div>
					</div>


					<div class="row" style="margin-bottom: 10px;">
						<div class="col-lg-6"
							style="width: 320px; float:left; margin-right:-20px; display:inline;">
							<label for="inputUsername" class="col-md-3 control-label">计费方式</label>
							<div class="col-md-9">
								<div class="input-icon">
									<select id="type" class="form-control">
										<option value="">--请选择--</option>
										<option value="balance">balance</option>
										<option value="time">time</option>
										<option value="count">count</option>
									</select>
								</div>
							</div>
						</div>
						<div class="col-lg-6"
							style="width: 320px; float:left; margin-right:-20px; display:inline;">
							<label for="inputUsername" class="col-md-3 control-label">账户类型</label>
							<div class="col-md-9">
								<div class="input-icon">
									<select id="accountType" class="form-control">
										<option value="">--请选择--</option>
										<option value="Person">个人</option>
										<option value="Group">机构</option>
									</select>
								</div>
							</div>
						</div>
					</div>
						<div id="showSeparator" style="margin-bottom: 30px;width: 590px;">
						<label for="inputUsername" class="col-md-3 control-label">描述
						</label>
						<div class="col-md-12">
							<div class="input-icon">
								<textarea id="description" rows="2" cols="20"
									class="form-control"></textarea>
							</div>
						</div>
					</div>
					<div id="showSeparator" style="margin-bottom: 30px;width: 750px;">
						<label for="inputUsername" class="col-md-3 control-label">产品列表
						</label>
						<div id="productsName" class="row" style="margin-bottom: 10px;">

						</div>
					</div>
					<!-- <div class="col-lg-6"
				style="width: 400px; float:left; margin-right:-20px;display:inline;">
				<label for="inputUsername" class="col-md-3 control-label">排序
				</label>
				<div class="col-md-9">
					<div class="input-icon">
						<input id="sort" type="text" class="form-control" />
					</div>
				</div>
			</div> -->
				</div>
			</div>
		</div>
	</div>

<script>
	var indexid = window.parent.getlay();
	var productDetail = "";
	$(function() {

		if (indexid != 0) {
			$.ajax({
				type : "post",
				url : "./productUpdate.do",
				data : {
					"id" : indexid,
				},
				dataType : "json",
				async : false,
				success : function(data) {
					$("#nameEn").val(data[0].nameEn);
					$("#nameZh").val(data[0].nameZh);
					$("#type").val(data[0].type);
					$("#accountType").val(data[0].accountType);
					$("#productDetail").val(data[0].productDetail);
					productDetail = data[0].productDetail;
					$("#description").val(data[0].description);
				},
				error : function(data) {
					alert("请求失败");
				}
			});
		}
		$
				.ajax({
					type : "post",
					url : "./repositoryIds.do",
					data : {},
					dataType : "json",
					async : false,
					success : function(data) {
						//alert(JSON.stringify(data));  
						$("#productsName").html("");
						var str = "";
						for ( var i = 0; i < data.length; i++) {
							str += "<div class='col-lg-1' style='width: 260px; float:left; margin-right:-20px;display:inline;'>";

							str += "<div class='col-md-9'>";
							str += "<div class='input-icon'>";
							str += "	<input type='checkbox' id='"+data[i].id+"' name='checkall' value="+data[i].id+" />&nbsp;&nbsp;";
							str += "	<label for='"+data[i].id+"' name='checkall'>"
									+ data[i].name;
							str += "</label></div>";
							str += "</div>";
							str += "</div>";
							//str+="<input type='checkbox' name='checkall' value="+data[i].id+" />"+data[i].nameZh+"";
						}
						$("#productsName").html(str);
						var classesids2 = productDetail.substring(0,
								productDetail.length - 1)
						var ids = classesids2.split(",");
						for ( var j = 0; j < ids.length; j++) {
							$("input[value=" + ids[j] + "]").attr("checked",
									true);
						}

					},
					error : function(data) {
						alert("请求失败");
					}
				});

	});

	function Page() {
		var value = [];
		$("input[name='checkall']:checked").each(function() {
			value.push($(this).val());
		});
		$.ajax({
			type : "post",
			url : "./productAddUpdate.do",
			data : {
				"id" : indexid,
				"nameEn" : $("#nameEn").val(),
				"nameZh" : $("#nameZh").val(),
				"type" : $("#type").val(),
				"accountType" : $("#accountType").val(),
				"productDetail" : value,
				"description" : $("#description").val(),
			},
			dataType : "json",
			async : false,
			traditional : true,
			success : function(data) {
				var index = parent.layer.getFrameIndex(window.name);
				window.parent.get();
				parent.layer.msg('提交成功');
				parent.layer.close(index);
			},
			error : function(data) {
				alert("请求失败");
			}
		});
	}
	//   默认单选函数
	function selected(selectname, selectid) {
		$("#" + selectname + " option").each(function() { //遍历全部option
			var v = $(this).val(); //获取option的内容
			if (v == selectid) {
				$(this).attr("selected", "selected");
			}
		});
	}
</script>


